package qiniu.voidcepc.voicepc.demos.web.vo;



/**
 * 增强版响应封装（带国际化支持）
 */
public class ApiResponse<T> {
    private final boolean success;
    private final String code;    // 业务状态码（字符串类型更灵活）
    private final T data;
    private final String i18nKey; // 国际化Key

    // 私有构造器
    private ApiResponse(Builder<T> builder) {
        this.success = builder.success;
        this.code = builder.code;
        this.data = builder.data;
        this.i18nKey = builder.i18nKey;
    }

    // ---------- 构建器模式 ----------
    public static class Builder<T> {
        private boolean success;
        private String code;
        private T data;
        private String i18nKey;

        public Builder<T> success(boolean success) {
            this.success = success;
            return this;
        }

        public Builder<T> code(String code) {
            this.code = code;
            return this;
        }

        public Builder<T> data(T data) {
            this.data = data;
            return this;
        }

        public Builder<T> i18nKey(String key) {
            this.i18nKey = key;
            return this;
        }

        public ApiResponse<T> build() {
            return new ApiResponse<>(this);
        }
    }

    // ---------- 快速构建方法 ----------
    public static <T> ApiResponse<T> ok(T data) {
        return new Builder<T>()
                .success(true)
                .code("200")
                .data(data)
                .build();
    }

    public static ApiResponse<?> error(String errorCode, String i18nKey) {
        return new Builder<>()
                .success(false)
                .code(errorCode)
                .i18nKey(i18nKey)
                .build();
    }

    // ---------- Getter ----------
    // ---------- Getter 方法（必须添加）----------
    public boolean isSuccess() {
        return success;
    }

    public String getCode() {
        return code;
    }

    public T getData() {
        return data;
    }

    public String getI18nKey() {
        return i18nKey;
    }
}
